﻿
@{
	ViewBag.Title = "课时管理";
	Layout = "~/Views/Shared/_AdminLayout.cshtml";
}

@section Header
{
<link href="~/assets/css/main.css" rel="stylesheet" />
<link href="~/assets/css/common.css" rel="stylesheet" />
<link href="~/assets/font-awesome-4.6.3/css/font-awesome.min.css" rel="stylesheet" />
<script src="~/assets/jquery-sortable/jquery-sortable.js"></script>
}

<ol class="breadcrumb">
	<li><a href="@Url.Action("CourseManager","Admin")">课程管理</a></li>
	<li><a href="#">@ViewBag.CourseName</a></li>
	<li>课时管理</li>
</ol>

<div class="col-md-2">
	<div class="list-group">
		<a href="@Url.Action("Course", "Admin", new { cid = ViewBag.CourseId })" class="list-group-item active">课程设置</a>
		<a href="@Url.Action("ClassHour", "Admin", new { cid = ViewBag.CourseId })" class="list-group-item ">课时管理</a>
		<a href="@Url.Action("FileManager", "Admin", new { cid = ViewBag.CourseId })" class="list-group-item ">文件管理</a>
		<a href="#" class="list-group-item ">试题管理</a>
	</div>
</div>

<div class="col-md-10">
	<div class="panel panel-default panel-col lesson-manage-panel" data-file-status-url="/course/12/manage/lesson/fileStatus" data-widget-cid="widget-1">
		  <input id="courseId" type="hidden" value="@ViewBag.CourseId" />
        <input id="HourId" type="hidden" value="" />
		  <div class="panel-heading" style="position: relative; top: auto; bottom: auto; left: auto; width: auto;">
			<div class="pull-right">

				<button class="btn btn-info btn-sm" id="lesson-create-btn" data-toggle="modal" data-target="#hour_modal" data-backdrop="static" data-keyboard="false" data-url="/course/12/manage/lesson/create"><i class="glyphicon glyphicon-plus"></i> 课时</button>

				<button class="btn btn-info btn-sm" id="lesson-create-btn" data-toggle="modal" data-target="#modal" data-backdrop="static" data-keyboard="false" data-url="/course/12/manage/lesson/create/testpaper"><i class="glyphicon glyphicon-plus"></i> 试卷</button>

				<div class="btn-group">
					<button type="button" class="btn btn-sm btn-success dropdown-toggle" data-toggle="dropdown">
						<i class="glyphicon glyphicon-plus"></i>章/节 <span class="caret"></span>
					</button>
					<ul class="dropdown-menu" role="menu">
						<li>
							<a href="#" id="chapter-create-btn" data-toggle="modal" data-target="#chapter_modal" ><i class="glyphicon glyphicon-plus"></i> 添加章</a>
						</li>
						<li>
							<a href="#" id="Section-create-btn" data-toggle="modal" data-target="#Section_modal"><i class="glyphicon glyphicon-plus"></i> 添加节</a>
						</li>
					</ul>
				</div>
			</div>
			课时管理
		</div>

		<div class="panel-body">
			<ul class="lesson-list sortable-list js-period-list" id="course-item-list" data-sort-url="/Admin/NodeSort">
				@foreach (LeEdu.DTO.Node item in ViewBag.Hours)
				{
					switch (item.Type)
					{
						case LeEdu.DTO.NodeType.Chapter:
							<li class="item-chapter js-chapter  clearfix" id="chapter-@item.Id">
								<div class="item-content">
									第 <span class="number">1</span> 章：
									@item.Name
								</div>
								<div class="item-actions prs">
									<div class="btn-group">
										<button class="btn btn-link dropdown-toggle" title="" data-toggle="dropdown" data-original-title="添加"><i class="glyphicon glyphicon-plus-sign"></i></button>
										<ul class="dropdown-menu" role="menu">
											<li>
                                                <a href="#" id="Section-create-btn" data-toggle="modal" data-target="#Section_modal" data-backdrop="static" data-keyboard="false" data-url="/course/12/manage/chapter/create?type=unit&amp;parentId=chapter-80"><i class="glyphicon glyphicon-plus"></i> 添加 节 </a>
											</li>
											<li>
                                                <a href="#" id="hour-create-btn" data-toggle="modal" data-target="#hour_modal" data-backdrop="static" data-keyboard="false" data-url="/course/12/manage/lesson/create?parentId=chapter-80"><i class="glyphicon glyphicon-plus"></i>  添加 课时  </a>
											</li>
											<li>
                                                <a href="#" id="-create-btn" data-toggle="modal" data-target="#modal" data-backdrop="static" data-keyboard="false" data-url="/course/12/manage/lesson/create/testpaper?parentId=chapter-80"><i class="glyphicon glyphicon-plus"></i> 添加 试卷 </a>
											</li>
										</ul>
									</div>

									<button class="btn btn-link" title="" data-toggle="modal" data-target="#modal" data-keyboard="false" data-url="/course/12/manage/chapter/80/edit" data-original-title="编辑"><i class="glyphicon glyphicon-edit"></i></button>

									<button class="btn btn-link delete-chapter-btn" title="" onclick="DelNode('@item.Id')" data-url="/course/12/manage/chapter/80/delete" data-chapter="章" data-part="节" data-original-title="删除"><i class="glyphicon glyphicon-trash"></i></button>
									<a href="javascript:;" class="btn-link pls" data-original-title="" title=""><i class="glyphicon glyphicon-chevron-up js-icon"></i></a>
								</div>
							</li>
							break;
						case LeEdu.DTO.NodeType.Section:
						<li class="item-chapter  item-chapter-unit clearfix" id="section-@item.Id" style="word-break: break-all;">
							<div class="item-content">
								第 <span class="number">1</span> 节：
								@item.Name
							</div>
							<div class="item-actions prs">
								<div class="btn-group">
									<button class="btn btn-link dropdown-toggle" title="" data-toggle="dropdown" data-original-title="添加"><i class="glyphicon glyphicon-plus-sign"></i></button>
									<ul class="dropdown-menu" role="menu">
										<li>
											<a href="#" id="hour_add" data-toggle="modal" data-target="#hour_modal" data-backdrop="static" data-keyboard="false" data-url="/course/12/manage/lesson/create?parentId=chapter-82"><i class="glyphicon glyphicon-plus"></i>  添加 课时  </a>
										</li>
										<li>
											<a href="#" id="chapter-create-btn" data-toggle="modal" data-target="#modal" data-backdrop="static" data-keyboard="false" data-url="/course/12/manage/lesson/create/testpaper?parentId=chapter-82"><i class="glyphicon glyphicon-plus"></i> 添加 试卷 </a>
										</li>
									</ul>
								</div>

								<button class="btn btn-link" title="" data-toggle="modal" data-target="#modal" data-keyboard="false" data-url="/course/12/manage/chapter/82/edit" data-original-title="编辑"><i class="glyphicon glyphicon-edit"></i></button>

								<button class="btn btn-link delete-chapter-btn" title="" onclick="DelNode('@item.Id')" data-url="/course/12/manage/chapter/82/delete" data-chapter="章" data-part="节" data-original-title="删除"><i class="glyphicon glyphicon-trash"></i></button>
							</div>
						</li>

							break;
						case LeEdu.DTO.NodeType.Hour:
						<li class="item-lesson clearfix" id="lesson-@item.Id" data-file-id="0" data-lesson-type="text">
							<div class="item-line"></div>
							<div class="item-content">
								<i class="fa fa-file-photo-o text-success"></i>
								课时 <span class="number">1</span>：
								@item.Name
								<span data-role="mediaStatus"></span>
							</div>

							<div class="item-actions">
                                <a class="btn btn-link" data-toggle="modal" data-target="#Video_modal"  data-backdrop="static" onclick="GetHourId('@item.Id')" data-keyboard="false" data-url="/course/12/manage/lesson/65/edit" data-original-title="" title=""><span class="es-icon es-icon-edit prs"></span>选择视频</a>
								
                                <a class="btn btn-link" href="/course/12/learn?preview=1#lesson/65" target="_blank" data-original-title="" title=""><span class="es-icon es-icon-visibility prs"></span>预览</a>
								<span class="dropdown">
									<a class="dropdown-toggle dropdown-more" id="dropdown-more" data-toggle="dropdown" href="#"><i class="es-icon es-icon-keyboardarrowdown" style="margin-right:3px" aria-haspopup="true" aria-expanded="false"></i>更多</a>
									<ul class="dropdown-menu pull-right dropdown-menu-more" role="menu" style="margin-top:12px;min-width:144px" aria-labelledby="dLabel">

										<li><a href="javascript:;" data-toggle="modal" data-target="#modal" data-url="/course/12/manage/lesson/65/material"><span class="glyphicon glyphicon-paperclip prs"></span>添加资料</a></li>
										<li class="divider"></li>
										<li class="hidden ">
											<a href="javascript:;" class="publish-lesson-btn" data-url="/course/12/manage/lesson/65/publish">
												<span class="glyphicon glyphicon-ok-circle prs"></span>发布
											</a>
										</li>
										<li class="">
											<a href="javascript:;" class="unpublish-lesson-btn" data-url="/course/12/manage/lesson/65/unpublish">
												<span class="glyphicon glyphicon-remove-circle prs"></span>取消发布
											</a>
										</li>
										<li class="hidden ">
											<a href="javascript:;" class="delete-lesson-btn" data-url="/course/12/manage/lesson/65/delete">
												<span class="glyphicon glyphicon-trash prs"></span>删除
											</a>
										</li>
									</ul>
								</span>
							</div>
						</li>
							break;
						default:
							break;
					}
				}
			</ul>
		</div>
	</div>
</div>
<input id="GetHourId" value="" type="hidden" />
<!--模态框：章-->
<div class="modal fade" id="chapter_modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
				<h4 class="modal-title" id="myModalLabel">添加章</h4>
			</div>
			<div class="modal-body">
				<form id="course-chapter-form" class="form-horizontal" method="post" data-parentid="" action="#" novalidate="novalidate" data-widget-cid="widget-29">
					<div class="row form-group">
						<div class="col-md-3 control-label">
							<label for="chapter-title-field">章标题</label>
						</div>
						<div class="col-md-8 controls">
							<input id="chapter-title-field" type="text" name="title" value="" class="form-control" data-widget-cid="widget-30" data-explain="">
							<div class="help-block" style="display:none;">
							</div>
						</div>
					</div>
					<input type="hidden" name="type" value="chapter">
				</form>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
				<button id="chapter_add" type="button" class="btn btn-primary">添加</button>
			</div>
		</div>
	</div>
</div>

<!--模态框：节-->
<div class="modal fade" id="Section_modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
				<h4 class="modal-title" id="myModalLabel">添加节</h4>
			</div>
			<div class="modal-body">
				<form id="course-chapter-form" class="form-horizontal" method="post" data-parentid="" action="#" novalidate="novalidate" data-widget-cid="widget-29">
					<div class="row form-group">
						<div class="col-md-3 control-label">
							<label for="chapter-title-field">节标题</label>
						</div>
						<div class="col-md-8 controls">
							<input id="Section-title-field" type="text" name="title" value="" class="form-control" data-widget-cid="widget-30" data-explain="">
							<div class="help-block" style="display:none;">
							</div>
						</div>
					</div>
					<input type="hidden" name="type" value="chapter">
				</form>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
				<button type="button" id="Section_add" class="btn btn-primary">添加</button>
			</div>
		</div>
	</div>
</div>
<!--模态框：课时-->
<div class="modal fade" id="hour_modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
				<h4 class="modal-title" id="myModalLabel">添加课时</h4>
			</div>
			<div class="modal-body">
				<form id="course-chapter-form" class="form-horizontal" method="post" data-parentid="" action="#" novalidate="novalidate" data-widget-cid="widget-29">
					<div class="row form-group">
						<div class="col-md-3 control-label">
							<label for="hour-title-field">课时标题</label>
						</div>
						<div class="col-md-8 controls">
							<input id="hour-title-field" type="text" name="title" value="" class="form-control" data-widget-cid="widget-30" data-explain="">
							<div class="help-block" style="display:none;">
							</div>
						</div>
					</div>
					<input type="hidden" name="type" value="chapter">
				</form>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" id="hour_add" onclick="hour_add()" class="btn btn-primary">添加</button>
			</div>
		</div>
	</div>
</div>



<!--选择视频文件-->
<div class="modal fade" id="Video_modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                <h4 class="modal-title" id="myModalLabel">选择视频文件</h4>
            </div>
            <div class="modal-body">
                <form id="course-chapter-form" class="form-horizontal" method="post" data-parentid="" action="#" novalidate="novalidate" data-widget-cid="widget-29">
                     






                    <div class="col-md-10">
                        <div class="panel panel-default panel-col">
                            @*<div class="panel-heading">
                                <a class="btn btn-info btn-xs pull-right add_course_file">
                                    <i class="glyphicon glyphicon-cloud-upload"></i>添加课程文件
                                </a>
                                课程文件
                            </div>*@

                            <div class="panel-body" id="file-manage-panel" data-file-status-url="/course/manage/file/status">
                                <table class="table table-striped table-hover" id="course-lesson-table">
                                    <thead>
                                        <tr>
                                            <th width="5%"><input type="checkbox" data-role="batch-select"></th>
                                            <th>文件名</th>
                                            <th>类型</th>
                                            <th>大小</th>
                                            <th>使用</th>
                                            <th>最后更新</th>
                                            <th>操作</th>
                                        </tr>
                                    </thead>
                                    <tbody>

                                        @for (int i = 0; i < ViewBag.Files.Count; i++)
                                        {
                                            var file = ViewBag.Files[i];

                                            <tr id="upload-file-tr-18" data-role="item" data-converthash="ch-coursematerial/5/20161008100010-93zhcg.doc">
                                                <td><input value="18" type="checkbox" data-role="batch-item"></td>
                                                <td>
                                                    <a href="#" target="_blank" rel="tooltip" title="" data-original-title=" @file.Name ">
                                                        @file.Name
                                                    </a>
                                                    <br><span class="label label-default tip">未转码</span>
                                                </td>
                                                <td>
                                                    @file.DocType
                                                </td>
                                                <td>  @file.Size </td>
                                                <td>
                                                    <span class="label label-default tip" data-original-title="" title="">@{var used = file.Used ? "已使用" : "未使用";}@used</span>
                                                </td>
                                                <td>
                                                    <span class="text-sm">
                                                        <a class="link-dark " href="#">admin</a>
                                                    </span>
                                                    <br>
                                                    <span class="text-muted text-sm">
                                                        @file.CreateTime
                                                    </span>
                                                </td>
                                                <td><a id="Video_Course" href="#" onclick="VideoBind('@file.Name','@file.Id')" class="btn btn-primary">用作教学</a></td>
                                            </tr>
                                        }

                                    </tbody>
                                </table>
  

                                <nav class="text-center">

                                </nav>

                            </div>
                        </div>

                    </div>
















                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>                
            </div>
        </div>
    </div>
</div>









<script src="~/assets/bootstrap-notify/bootstrap-notify.min.js"></script>
<script type="text/javascript">



	var sort = function ($list) {
		var lessonNum = chapterNum = unitNum = 0;
		$list.find('.item-lesson, .item-chapter').each(function () {
			var $item = $(this);
			if ($item.hasClass('item-lesson')) {
				lessonNum++;
				$item.find('.number').text(lessonNum);
			} else if ($item.hasClass('item-chapter-unit')) {
				unitNum++;
				$item.find('.number').text(unitNum);
			} else if ($item.hasClass('item-chapter')) {
				chapterNum++;
				unitNum = 0;
				$item.find('.number').text(chapterNum);
			}
		});
	}

	$(function () {
		var $list = $("#course-item-list").sortable({
			distance: 20,
			itemSelector: '.item-lesson, .item-chapter',
			onDrop: function (item, container, _super) {
				_super(item, container);
				sortList($list);
			},
			serialize: function (parent, children, isContainer) {
				return isContainer ? children : parent.attr('id');
			},
			isValidTarget: function (item, container) {
				if (item.siblings('li').length) {
					return true;
				} else {
					return false;
				}
			}
		});

		sort($list);

		var sortList = function ($list) {
			var data = $list.sortable("serialize").get();
			$.post($list.data('sortUrl'), { ids: data }, function (response) {
				sort($list);
			});
		};
	   
		$("#chapter_add").click(function () {
			var title = $("#chapter-title-field").val();
			var courseId = $("#courseId").val();
			$.ajax({
				url: "/Admin/AddChapter",
				type: "post",
				data: { title: title, courseId: courseId },
				success: function (data) {
					
					$.notify({
						message: '添加成功',
						timer: 2000
					}, {
						type: 'success'
					});

					$("#chapter_modal").modal('hide');
					location.reload();
				}
			});
		});




		$("#Section_add").click(function () {
			var title = $("#Section-title-field").val();
			var courseId = $("#courseId").val();
			$.ajax({
				url: "/Admin/AddSection",
				type: "post",
				data: { title: title, courseId: courseId },
				success: function (data) {
					
						$.notify({
							message: '添加成功',
							timer: 2000
						}, {
							type: 'success'
						});
					 
						$("#Section_modal").modal('hide');
						location.reload();
					   
						
					
					
				}
			});
		});

		
		 
	});

	function hour_add() {

	    var title = $("#hour-title-field").val();
	    var courseId = $("#courseId").val();
	    $.ajax({
	        url: "/Admin/AddHour",
	        type: "post",
	        data: { title: title, courseId: courseId },
	        success: function (data) {

	            $.notify({
	                message: '添加成功',
	                timer: 2000
	            }, {
	                type: 'success'
	            });

	            $("#hour_modal").modal('hide');
	            location.reload();




	        }
	    });
	}


	function DelNode(id)
	{
	    confirm('确认要删除吗？');
	    $.ajax({
	        url: "/Admin/DelNode",
	        type: "post",
	        data: { id: id},
	        success: function (data) {
	            if(data)
	            {
	                location.reload();
	            }
	            else
	            {
	                alert("处理失败！");
	            }
	        }
	    });
	}

	function DelHour(id)
	{
	    confirm('确认要删除吗？');
	    $.ajax({
	        url: "/Admin/DelHour",
	        type: "post",
	        data: { id: id},
	        success: function (data) {
	            if(data)
	            {
	                location.reload();
	            }
	            else
	            {
	                alert("处理失败！");
	            }
	        }
	    });
	}
	function GetHourId(HourId)
	{
	    $("#GetHourId").val(HourId);
	}
	function VideoBind(filename,fileid)
	{
	    var f_name = filename;	   
	    var h_id = $("#GetHourId").val();
	    var c_id = '@ViewBag.CourseId';
	    var f_id = fileid;
	    $.ajax({
	        url: "/Admin/VideoBind",
	        type: "post",
	        data: {
	            cid: c_id,
	            fname: f_name,
	            hid: h_id,
	            fid: f_id
	        },
	        success: function (data) {
	            if (data) {
	                $("#doing").hide();
	                $("#success").show();
	                setTimeout(function () {
	                    $("#Video_modal").modal('hide');
	                    window.location.reload();
	                }, 1000);

	            }
	            else {
	                $("#doing").hide();
	                $("#error").show();
	            }
	        }
	    });
	}
	  
 
</script>